<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
    return view('welcome');
});
Route::get('q', function () {
    return view('q',['p'=>'ppp'])->with(['user'=>"haha",'age'=>22]);
});
/*
 * response
 * text/html    text/plain
 */
Route::get('hello',function (){
    return response(["<span>1</span>",1],201)->header('content-type','text/plain');

});
/*
 * 文件下载
 */
Route::get('h1',function (){
    return response()->download("index.php",'my.php');
});
 /*
  * 路由跳转到外部
  */
Route::get('h2',function (){
    return redirect("http://www.baidu.com");
});
Route::get('h3',function (){
    return redirect("login");
});
/*
 * 路由跳转到内部
 */
Route::get('test',"Test\TestController@index");
Route::get('t1',"Test\TestController@t1");
Route::get('ck',"Test\TestController@ck");
Route::get('se',"Test\TestController@se");
Route::get('insertJob',"Test\JobController@insertJob");

/*
 * 正则
 */
Route::get("t2/{n}/{p}/{w?}",function ($n,$p){
        return 'n:'.$n."-p:".$p;
        })->where(
            [
                'n'=>'\d+',
                'p'=>'[a-z]+',
                'w'=>'(\w+\.html)|(\w+)'
            ]
);
Route::match(['get','post'],'login',"Admin\LoginController@login")->name('login');
Route::group(['prefix'=>'t'],function (){
    Route::get('t1',function (){
        return array(1,2,3,4,5);
    });
});
Route::group(['prefix'=>'s','middleware'=>'auth','namespace'=>'aa'],function (){
    Route::get('s1',function (){
        return 'auth.s';
    });
});

/*
 * 资源型
 *  artisan make:controller Admin\UserController --resource
 */
//Route::namespace("Admin")->resource("u","UserController");
Route::group(['namespace'=>"Admin","prefix"=>"admin"],function (){
    Route::middleware("auth")->resource("u","UserController")->only(['index']);
    Route::middleware("auth")->resource("u","UserController")->except(['show']);
});

/*
 * api型php artisan make:controller Admin/ApiController --api
 */
Route::group(['namespace'=>"Admin","prefix"=>"i"],function (){
    Route::apiResources(["a"=>"ApiController"]);
});


